//定义模块化，获取状态数据
export const getters = {
  //写法如下：
  // getCount: state => state.num.count,
  // getUser:state=>state.user.user
  cartList: (state) => state.Cart.cartList,
  collectionList: (state) => state.Cart.collectionList,
  stateAll: (state) => state.Cart.stateAll,
  totalPrice: (state) => {
    let cartList = state.Cart.cartList;
    let total = cartList.reduce(
      (previous, current) =>
        previous + (current.state ? current.price * current.num : 0),
      0
    );
    return total * 100;
  },

  addressList: (state) => state.Address.addressList,
  // 获取已登录的用户信息
  getUser: (state) => state.User.user,
  getToken: (state) => state.User.token,

  //获取首页切换的城市
  getCity: (state) => state.Address.onChangeCity,
};
